<?php
function view_bckabout($config,$param) {
    $db = new db($config);
    $result = $db->query("SELECT * FROM aboutus WHERE 1");
	$desc = $db->query("SELECT * FROM deskripsi WHERE page ='aboutus'");
    $param['aboutus'] = true;
    $param['loggedin'] = true;
    view_backend_header($config, $param);
    ?>
    <?php
    //verifikasi isian gunakan javascript
    if (isset($_SESSION['editted'])) {
        echo '<div class="alert alert-warning">'.$_SESSION['editted'].'</div>';
        unset($_SESSION['editted']);
    }
    ?>
	<div>
        <form method="post" action="<?php echo $config['home_url']."backend/edaboutdesc"?>">
            <div>Deskripsi : <textarea textarea class="descbck" name="descabout"><?php echo $desc[0]['deskripsi']; ?></textarea>
            <div><input class="btn" type="submit" value="Ubah" name="ubah" /></div>
        </form>
    </div>
	<h3 onclick="javascript:showHide('foto');">Slide++</h3>
	<div id="foto" style="display:none">
		<form action="<?php echo $config['home_url']."backend/edaboutfoto"?>" method="post" enctype="multipart/form-data">
			<div>Gambar : <input type='file' name='gambar'/></div>
			<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
		</form>
		<div><?php
			$uploaddir = $config['image_path'].'about-us'.DIRECTORY_SEPARATOR;
			$limitedext = array("jpg","jpeg","png","bmp");
			$cfiles = 0;
			$files = scandir($uploaddir.'pre'.DIRECTORY_SEPARATOR);
			for($i = 0; $i < count($files); $i++) {
				$file = $files[$i];
				$getExt = explode('.',$file);
				$file_ext = $getExt[count($getExt)-1];
				if (in_array($file_ext,$limitedext)) {
					?>
					<div style="float:left">
						<div class='gallery-thumb' id='gallery-thumb-<?php echo $cfiles; ?>' style='max-width:120px;max-height:50px;overflow:hidden;'>
							<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."about-us/pre/".$file; ?>" alt="<?php echo $file; ?>" /></a>
						</div>
						<div align="center">
							<div><a class="ahapus" href="<?php echo $config['home_url']."backend/delaboutfoto?img=$file"?>">(X)</a></div>
						</div>
					</div>
					<?php
					$cfiles++;
				}
			}
			if ($cfiles<1){
				echo '<div class="judul-gale"><h4>Tidak terdapat slide saat ini</h4></div>';
			}?>
			<div style="clear:both"></div>
		</div>
	</div>
	<h3 onclick="javascript:showHide('anggota');">Anggota++</h3>
    <div id="anggota" style="display:none">
        <form method="post" action="<?php echo $config['home_url']."backend/edaboutangg"?>" enctype="multipart/form-data">
            <div>Nama : <input type="text" name="namaplus" /></div>
            <div class="input-prepend"><span class="add-on">facebook.com/</span><input type="text" name="fbplus" /></div>
            <div>Email : <input type="text" name="emplus" /></div>
			<div>Nomor Kontak : <input type="text" name="kontakplus" /></div>
			<div>Title : <input type="text" name="titplus" /></div>
			<div>Deskripsi : <textarea textarea class="descbck" name="descplus"></textarea>
			<div>Foto Profil : <input type="file" name="ppplus" /></div>
			<div>Foto Anggota : <input type="file" name="anggplus" /></div>
            <div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
        </form>
		<div>
			<?php
			echo "<ul>";
			foreach ($result as $res){
				//echo "<li><a href=\"".$config['home_url']."backend/aboutus/".$res['idAbout']."\">".$res['nama']."</a></li>";
				echo "<li><a href=\"javascript:showHide('agg".$res['idAbout']."');\">".$res['nama']."</a> <a href=\"".$config['home_url']."backend/delabout/".$res['idAbout']."\">(X)</a>";
				echo "<div style=\"display:none\"id=\"agg".$res['idAbout']."\">";
					//echo $config['home_url']."backend/kutipan/".$res['idkutipan'];
					echo "<form method=\"post\" action=\"".$config['home_url']."backend/edaboutangg"."\">";
						echo "<input type=\"hidden\" name=\"id\" value=\"".$res['idAbout']."\" />";
						echo "<div>Nama : <input type=\"text\" name=\"namaped\" value=\"".$res['nama']."\" /></div>";
						echo "<div class=\"input-prepend\"><span class=\"add-on\">facebook.com/</span><input type=\"text\" name=\"fbed\" value=\"".$res['idFB']."\" /></div>";
						echo "<div>Email : <input type=\"text\" name=\"emed\" value=\"".$res['email']."\" /></div>";
						echo "<div>Nomor Kontak : <input type=\"text\" name=\"kontaked\" value=\"".$res['kontak']."\" /></div>";
						echo "<div>Title : <input type=\"text\" name=\"tited\" value=\"".$res['title']."\" /></div>";
						echo "<div>Deskripsi : <textarea textarea class=\"descbck\" name=\"desced\">".$res['desc']."</textarea>";
						echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
					echo "</form><br />";
					echo "<div>";	//PP
						$uploaddir = $config['image_path'].'about-us'.DIRECTORY_SEPARATOR.'pp'.DIRECTORY_SEPARATOR;
						$cfiles = 0;
						$regex = $uploaddir.$res['idAbout'].".*";
						//FILTER
						foreach (glob($regex) as $files) {
							$getFile = explode(DIRECTORY_SEPARATOR,$files);
							$file = $getFile[count($getFile)-1];
							?>
							<div id='download-thumb-<?php echo $cfiles; ?>'>
								<h4>Foto Profil</h4>
								<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."about-us/pp/".$file; ?>" alt="<?php echo $file; ?>" /> <a class="ahapus" href="<?php echo $config['home_url']."backend/delaboutanggpp?img=$file"?>">(X)</a>
							</div>
							<?php
							$cfiles++;
							break;
						}
						if ($cfiles<1){
							echo '<div class="judul-gale"><h4>Tidak terdapat foto profil saat ini</h4></div>';
							?>
							<form action="<?php echo $config['home_url']."backend/addaboutanggpp"?>" method="post" enctype="multipart/form-data">
								<input type="hidden" name="idk" value="<?php echo $res['idAbout']; ?>"
								<div>Foto Profil : <input type='file' name='pp'/></div>
								<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
							</form>
						<?php }
					echo "</div><br />";
					echo "<div>";	//FOTO ANGGOTA
						$uploaddir = $config['image_path'].'about-us'.DIRECTORY_SEPARATOR.'anggota'.DIRECTORY_SEPARATOR;
						$cfiles = 0;
						$regex = $uploaddir.$res['idAbout'].".*";
						//FILTER
						foreach (glob($regex) as $files) {
							$getFile = explode(DIRECTORY_SEPARATOR,$files);
							$file = $getFile[count($getFile)-1];
							?>
							<div id='download-thumb-<?php echo $cfiles; ?>'>
								<h4>Foto Anggota</h4>
								<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."about-us/anggota/".$file; ?>" alt="<?php echo $file; ?>" /> <a class="ahapus" href="<?php echo $config['home_url']."backend/delaboutanggfoto?img=$file"?>">(X)</a>
							</div>
							<?php
							$cfiles++;
							break;
						}
						if ($cfiles<1){
							echo '<div class="judul-gale"><h4>Tidak terdapat foto anggota saat ini</h4></div>';
							?>
							<form action="<?php echo $config['home_url']."backend/addaboutanggfoto"?>" method="post" enctype="multipart/form-data">
								<input type="hidden" name="idk" value="<?php echo $res['idAbout']; ?>"
								<div>Foto Anggota : <input type='file' name='pp'/></div>
								<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
							</form>
						<?php }
					echo "</div>";
				echo "</div></li>";
			}
			echo "</ul>";
			?>
		</div>
	</div>
    <?php
    view_backend_footer($config, $param);
}
